<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>10.函数节流</title>
		<script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>

	</head>
	<body>
		<button id="btn">点我发送请求</button>

		<script type="text/javascript" >
			//获取元素
			const btn = document.getElementById('btn')
			
			//靠定时器+标识实现节流
			/* let timeId 
			let canDo = true
			btn.onclick = ()=>{
				if(canDo){
					console.log('发送请求~~~')
					canDo = false
					setTimeout(()=>{
						canDo = true
					},5000)
				}
			} */

			//靠lodash节流
			btn.onclick = _.throttle(()=>{
				console.log('发送请求~~~')
			},2000,{leading:false,trailing:false})
		</script>
	</body>
</html>